package com.service;


import com.dao.CourseDAO;
import com.dao.StudentDAO;
import com.pojo.Course;
import com.pojo.Student;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Service
@Transactional
public class StudentService {

    @Autowired
    private StudentDAO studentDAO;

    @Autowired
    private CourseDAO  courseDAO;

    /**
     *
     * @param sid 学号
     * @param cids 课程
     */
    public void addXuan(int sid, int ...cids)
    {
        Student stu = studentDAO.findById(sid).get();
        List course = new ArrayList();
        for (int cid : cids)
        {
            Course c = courseDAO.findById(cid).get();
            course.add(c);
        }
        //stu.getCs().clear();; //原来的不要
        stu.getCs().addAll(course);
        studentDAO.save(stu);

    }


}
